<?php
namespace app\common\validate;
use think\Validate;
use think\Request;
class Zans extends Validate{
    protected $rule =   [
    'contentid' => 'number',
    ];

    protected $message  =   [

    ];
    protected $scene = [
    'check_contentid' => ['contentid'=>'require|checkContentid'],
    ];
    
    protected function checkContentid($value, $rule=[], $data){
        //$count = model("Zans")->where($data)->count();
        if ($data['typeid']==2) {
          $count = model("Zans")->where('contentid',$data['contentid'])->where('userid',$data['userid'])->count();
            if ($count) {
                return '需求只能点赞一次';
            }
        }else{
          $count = model("Zans")->where($data)->whereTime('addtime', 'd')->count();
            if ($count) {
                return '今天已点赞';
            }
        }
        return true;
   }
}